home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 38
/
Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso
/
Aminet
/
gfx
/
pbm
/
netpbmwos.lha
/
netpbm
/
Netpbm.programming
< prev
next >
Wrap
Text File
|
2000-05-29
|
4KB
|
95 lines
This file is an attempt to give some basic guidelines for those who
wish to write new Netpbm programs. The guidelines ensure:
A) Your program functions consistently with the rest of the package.
B) Your program works in myriad environments on which you can't test it.
C) You don't miss an important details of the Netpbm formats.
D) Your program is immune to small changes in the Nepbm formats.
The easiest way to write your own facility, is to take an existing
one, similar to the one you want to write, and to modify it. This
saves a lot of time, and ensures conformity with these rules.
The Netpbm maintainer accepts programs that do not meet these guidelines,
so don't feel you need to hold back a contribution because you wrote it
before you read these.
* See the libp?m.3 man pages for documentation of the various library
routines you should use to read and write Netpbm images and perform
other common operations.
* See the p?m.5 man pages for specifications of the Netpbm formats, but
don't depend very much on these; use the library functions instead to
read and write the image files.
* Your new program must belong to one of the four Netpbm formats,
i.e. pbm, pgm, ppm or pnm. They are defined as follows:
pbm: Bitmaps only, i.e. a pixel is either black or white.
pgm: Gray scales, i.e. a pixel can have any value between black
and white, but no colours.
ppm: Colour images. Note that Netpbm does not support the use of
look up tables.
pnm: A facility able to create or read more than one of the formats
above. Note that all pgm programs can automatically read pbm
images, and that all ppm programs can automatically read both
pbm and pgm files. A pnm utility does more than this, its action
depends on the type of the input file. E.g. the pnmtotiff utility
creates a bitmap TIFF file when it reads a pbm file on its input,
a gray scale TIFF files when it reads a pgm file on its input, etc.
ppmtogif on the other hand treats a pbm file on its input exactly
as if it were a ppm file with only the colours black and white.
Decide which one of these formats your program belongs to.
* If you want to use global variables or global functions in your program,
make them static, so that they won't cause problems to other programs
when you compile a merged binary (see the Makefile).
* Declare main as: int main(argc, argv), not void! Some systems won't
compile void main().
* Always start the code in main() with a call to p?m_init().
* Use pm_error() and pm_message() for error messages and other messages.
* Don't forget to write a proper manual page!
* Properly use maxvals. As explained in the format specifications, every
sample value in an image must be interpreted relative to the image's
maxval. For example, a pixel with value 24 in an image with maxval 24
is the same brightness as a pixelwith value 255 in an image with a
maxval of 255.
255 is a popular maxval (use the PPM_MAXMAXVAL etc. macros) because it
makes samples fit in a single byte and at one time was the maximum
possible maxval in the format.
Note that the Pnmdepth program converts an image from one maxval to
another.
* Don't include extra function. If you can already do something by
piping the input or output of your program through another Netpbm
program, don't make an option on your program to do it. That's the
Netpbm philosophy -- simple building blocks.
Similarly, if your program does two things which would be useful
separately, write two programs and advise users to pipe them
together.
* Your program should, if appropriate, allow the user to use Standard
Input and Output for images. This is because Netpbm users commonly
use pipes.
* Contrary to what you see in the old programs you may use as an
example, you may use just ANSI C and POSIX C library functions. All
modern Netpbm users use those. Look at the HISTORY file and find a
recent addition to Netpbm to use as an example.